home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / ddj9304.zip / WAVELET.ZIP / ANALYZER.C next >
Text File  |  1992-05-17  |  23KB  |  698 lines

  1. /* ANALYZER.C */
  2.  
  3. #include <dos.h>
  4. #include <bios.h>
  5. #include <stdlib.h>
  6.  
  7. #include "dsp_ctrl.h"
  8. #include "v592x480.h"
  9. #include "wave_bld.h"
  10. #include "analyzer.h"
  11.  
  12. int CopyString(char *src_str, char *dest_str, int maxlen);
  13. emtype StartEntry(char *src_str, char *dest_str, int top, int *cur_pos);
  14. void main(void);
  15.  
  16.  
  17. int CopyString(char *src_str, char *dest_str, int maxlen)
  18. {
  19.     int i;
  20.     i = 0;
  21.     do
  22.     {
  23.         dest_str[i] = src_str[i];
  24.         i++;
  25.     } while ((src_str[i] != '\0') && (i < maxlen));
  26.  
  27.     dest_str[i] = '\0'; /* add null to end of destination */
  28.     return i;
  29. }
  30.  
  31.  
  32. emtype StartEntry(char *src_str, char *dest_str, int top, int *cur_pos)
  33. {
  34.     DrawString(STATIC_PAGE, top, 11, BLACK, src_str); /* draw current string */
  35.     *cur_pos = CopyString(src_str, dest_str, 12);    /* make copy for editing */
  36.     DrawChar(STATIC_PAGE, top, *cur_pos+11, BLACK, '_'); /* draw cursor */
  37.     return START;
  38. }
  39.  
  40.  
  41. void main()
  42. {
  43.     tftype quit, DSPrunning, hold;
  44.     curpos cursor_at, bottom_control;
  45.     emtype entry_mode;
  46.     int count, i, s, c, looking_at, cursor_pos, DSPfiltlen;
  47.     unsigned new_image, source_page;
  48.     unsigned long image_location;
  49.     union REGS regset;
  50.     double entry;
  51.     float wavefilters[12];
  52.  
  53.     union
  54.     {
  55.         char c[2];
  56.         int i;
  57.     } key;
  58.  
  59.     /* initialize the configuration of the DSP board */
  60.     DSPboardConfigure();
  61.  
  62.     /* download default parameters and coefficients for wavelet transform */
  63.     SetupWaveletConstruction();
  64.     BuildDSPfilterArray(alpha, beta, wavefilters); /* initial wavelet is DAUB4 */
  65.     DownloadDecompCoeffs(FILTER_LENGTH_4);
  66.     DownloadFiltCoeffs(wavefilters);
  67.  
  68.     /* download initial image scalling factors */
  69.     for (i = 0; i < 8; i++)
  70.         DownloadTraceScale(i, trace_scale[i]);
  71.  
  72.     Set592x480(); /* set to 592x480 16-color mode */
  73.  
  74.     /* initialize screen colors for Page 0 */
  75.     DrawObject(PAGE_0, flip_screens);
  76.     DrawString(PAGE_0, 8, 3, BLACK, "INPUT");
  77.     DrawString(PAGE_0, 58, 2, BLACK,  "DETAIL");
  78.     DrawString(PAGE_0, 66, 2, BLACK,  "LEVEL 5");
  79.     DrawString(PAGE_0, 108, 2, BLACK, "LEVEL 4");
  80.     DrawString(PAGE_0, 158, 2, BLACK, "LEVEL 3");
  81.     DrawString(PAGE_0, 208, 2, BLACK, "LEVEL 2");
  82.     DrawString(PAGE_0, 258, 2, BLACK, "LEVEL 1");
  83.     DrawString(PAGE_0, 308, 2, BLACK, "LEVEL 0");
  84.     DrawString(PAGE_0, 358, 2, BLACK, "APPROX");
  85.     DrawString(PAGE_0, 366, 2, BLACK, "LEVEL 0");
  86.  
  87.     /* initialize screen colors for Page 1 */
  88.     DrawObject(PAGE_1, flip_screens);
  89.     DrawString(PAGE_1, 8, 3, BLACK, "INPUT");
  90.     DrawString(PAGE_1, 58, 2, BLACK,  "DETAIL");
  91.     DrawString(PAGE_1, 66, 2, BLACK,  "LEVEL 5");
  92.     DrawString(PAGE_1, 108, 2, BLACK, "LEVEL 4");
  93.     DrawString(PAGE_1, 158, 2, BLACK, "LEVEL 3");
  94.     DrawString(PAGE_1, 208, 2, BLACK, "LEVEL 2");
  95.     DrawString(PAGE_1, 258, 2, BLACK, "LEVEL 1");
  96.     DrawString(PAGE_1, 308, 2, BLACK, "LEVEL 0");
  97.     DrawString(PAGE_1, 358, 2, BLACK, "APPROX");
  98.     DrawString(PAGE_1, 366, 2, BLACK, "LEVEL 0");
  99.  
  100.     for(i = 0; i < 8; i++)
  101.     {
  102.         s = trace_scale[i];
  103.         DrawString(PAGE_0, control_loc[i], 4, BLACK, trace_scale_str[s]);
  104.         DrawString(PAGE_1, control_loc[i], 4, BLACK, trace_scale_str[s]);
  105.         DrawChar(PAGE_0, control_loc[i], 2, BLACK, 0x10);
  106.         DrawChar(PAGE_1, control_loc[i], 2, BLACK, 0x10);
  107.     }
  108.  
  109.     /* initialize screen colors for Page 2 */
  110.     DrawObject(STATIC_PAGE, static_screen);
  111.  
  112.     s = control_loc[i++];
  113.     DrawString(STATIC_PAGE, s, 4, BLACK, "HOLD");
  114.     DrawChar(STATIC_PAGE, s, 2, BLACK, 0x10);
  115.     s = control_loc[i++];
  116.     DrawString(STATIC_PAGE, s, 4, BLACK, "RUN");
  117.     DrawChar(STATIC_PAGE, s, 2, BLACK, 0x10);
  118.     s = control_loc[i++];
  119.     DrawString(STATIC_PAGE, s, 4, BLACK, "ALPHA");
  120.     DrawChar(STATIC_PAGE, s, 2, BLACK, 0x10);
  121.     s = control_loc[i++];
  122.     DrawString(STATIC_PAGE, s, 4, BLACK, "BETA");
  123.     DrawChar(STATIC_PAGE, s, 2, BLACK, 0x10);
  124.     s = control_loc[i++];
  125.     DrawString(STATIC_PAGE, s, 4, BLACK, "QUIT");
  126.     DrawChar(STATIC_PAGE, s, 2, RED, 0x10);
  127.  
  128.     /* initialize scaling and wavelet function windows */
  129.     DrawObject(STATIC_PAGE, wavelet_window);
  130.     DrawGraph(209, 5, 531, 65, PhiData + offset, magnitude, 320, OLIVE, 1);
  131.     DrawGraph(209, 5, 531, 65, PsiData + offset, magnitude, 320, CYAN, 1);
  132.     DrawString(STATIC_PAGE, 70, 29, BLACK, "SCALLING FUNCTION");
  133.     DrawString(STATIC_PAGE, 70, 51, BLACK, "WAVLET FUNCTION");
  134.     ColorRectangle(STATIC_PAGE, 215, 72, 225, 74, OLIVE);
  135.     ColorRectangle(STATIC_PAGE, 391, 72, 401, 74, CYAN);
  136.     DrawString(STATIC_PAGE, control_loc[ALPHA], 11, BLACK, alpha_str);
  137.     DrawString(STATIC_PAGE, control_loc[BETA], 11, BLACK, beta_str);
  138.  
  139.     quit = FALSE;
  140.     DSPrunning = FALSE;
  141.     hold = FALSE;
  142.     cursor_at = QUIT;     /* all controls are accessible */
  143.     bottom_control = QUIT;
  144.     looking_at = PAGE_0;
  145.     do                    /* enter control loop */
  146.     {
  147.         if (bioskey(1))
  148.         {
  149.             key.i = bioskey(0);
  150.             if (!key.c[0])
  151.             {
  152.                 switch (key.c[1])
  153.                 {
  154.                     case 0x48:    /* Up Arrow */
  155.                         if (cursor_at == INPUT)  /* can't go any further */
  156.                             break;
  157.  
  158.                         s = control_loc[cursor_at];
  159.                         if (cursor_at < HOLDCONT) /* turn off marker on both pages */
  160.                         {
  161.                             DrawChar(PAGE_0, s, 2, BLACK, 0x10);
  162.                             DrawChar(PAGE_1, s, 2, BLACK, 0x10);
  163.                         }
  164.                         else /* turn off marker on single page */
  165.                         {
  166.                             if (cursor_at == ALPHA) /* disable alpha entry field */
  167.                             {
  168.                                 ColorRectangle(STATIC_PAGE, 88, s-2, 191, s+8, PALE_YELLOW);
  169.                                 DrawString(STATIC_PAGE, s, 11, BLACK, alpha_str);
  170.                             }
  171.                             else if (cursor_at == BETA) /* disable beta entry field */
  172.                             {
  173.                                 ColorRectangle(STATIC_PAGE, 88, s-2, 191, s+8, PALE_YELLOW);
  174.                                 DrawString(STATIC_PAGE, s, 11, BLACK, beta_str);
  175.                             }
  176.  
  177.                             DrawChar(STATIC_PAGE, s, 2, BLACK, 0x10);
  178.                         }
  179.  
  180.                         cursor_at--; /* move cursor and get vertical positioning */
  181.                         s = control_loc[cursor_at];
  182.                         if (cursor_at < HOLDCONT) /* turn on marker on both pages */
  183.                         {
  184.                             DrawChar(PAGE_0, s, 2, RED, 0x10);
  185.                             DrawChar(PAGE_1, s, 2, RED, 0x10);
  186.                         }
  187.                         else /* turn on marker for single page */
  188.                         {
  189.                             if (cursor_at == ALPHA) /* enable alpha entry field */
  190.                             {
  191.                                 ColorRectangle(STATIC_PAGE, 88, s - 2, 191, s + 8, LT_GRAY);
  192.                                 entry_mode = StartEntry(alpha_str, entry_str, s, &cursor_pos);
  193.                             }
  194.  
  195.                             else if (cursor_at == BETA) /* enable beta entry field */
  196.                             {
  197.                                 ColorRectangle(STATIC_PAGE, 88, s - 2, 191, s + 8, LT_GRAY);
  198.                                 entry_mode = StartEntry(beta_str, entry_str, s, &cursor_pos);
  199.                             }
  200.  
  201.                             DrawChar(STATIC_PAGE, s, 2, RED, 0x10);
  202.                         }
  203.  
  204.                         break;
  205.  
  206.                     case 0x49:    /* PGUP */
  207.                         s = control_loc[cursor_at];
  208.                         if (cursor_at < HOLDCONT) /* turn off marker on both pages */
  209.                         {
  210.                             DrawChar(PAGE_0, s, 2, BLACK, 0x10);
  211.                             DrawChar(PAGE_1, s, 2, BLACK, 0x10);
  212.                         }
  213.                         else /* turn off marker on single page */
  214.                         {
  215.                             if (cursor_at == ALPHA) /* disable alpha entry field */
  216.                             {
  217.                                 ColorRectangle(STATIC_PAGE, 88, s-2, 191, s+8, PALE_YELLOW);
  218.                                 DrawString(STATIC_PAGE, s, 11, BLACK, alpha_str);
  219.                             }
  220.                             else if (cursor_at == BETA) /* disable beta entry field */
  221.                             {
  222.                                 ColorRectangle(STATIC_PAGE, 88, s-2, 191, s+8, PALE_YELLOW);
  223.                                 DrawString(STATIC_PAGE, s, 11, BLACK, beta_str);
  224.                             }
  225.  
  226.                             DrawChar(STATIC_PAGE, s, 2, BLACK, 0x10);
  227.                         }
  228.  
  229.                         cursor_at = INPUT; /* place cursor at top */
  230.                         DrawChar(PAGE_0, control_loc[INPUT], 2, RED, 0x10);
  231.                         DrawChar(PAGE_1, control_loc[INPUT], 2, RED, 0x10);
  232.                         break;
  233.  
  234.                     case 0x4b:    /* Left Arrow */
  235.                         if ((cursor_at < HOLDCONT) && (trace_scale[cursor_at] > 0))
  236.                         {                              /* increase vertical scale */
  237.                             trace_scale[cursor_at] -= 1;
  238.                             s = trace_scale[cursor_at];
  239.                             i = control_loc[cursor_at];
  240.                             c = control_color[cursor_at];
  241.                             ColorRectangle(PAGE_0, 32, i, 71, i + 8, c);
  242.                             ColorRectangle(PAGE_1, 32, i, 71, i + 8, c);
  243.                             DrawString(PAGE_0, i, 4, BLACK, trace_scale_str[s]);
  244.                             DrawString(PAGE_1, i, 4, BLACK, trace_scale_str[s]);
  245.                             DownloadTraceScale(cursor_at, s);
  246.                         }
  247.                         break;
  248.  
  249.                     case 0x4d:    /* Right Arrow */
  250.                         if ((cursor_at < HOLDCONT) && (trace_scale[cursor_at] < 9))
  251.                         {                              /* decrease vertical scale */
  252.                             trace_scale[cursor_at] += 1;
  253.                             s = trace_scale[cursor_at];
  254.                             i = control_loc[cursor_at];
  255.                             c = control_color[cursor_at];
  256.                             ColorRectangle(PAGE_0, 32, i, 71, i + 8, c);
  257.                             ColorRectangle(PAGE_1, 32, i, 71, i + 8, c);
  258.                             DrawString(PAGE_0, i, 4, BLACK, trace_scale_str[s]);
  259.                             DrawString(PAGE_1, i, 4, BLACK, trace_scale_str[s]);
  260.                             DownloadTraceScale(cursor_at, s);
  261.                         }
  262.                         break;
  263.  
  264.                     case 0x50:    /* Dn Arrow */
  265.                         if (cursor_at == bottom_control)  /* can't go any further */
  266.                             break;
  267.  
  268.                         s = control_loc[cursor_at];
  269.                         if (cursor_at < HOLDCONT) /* turn off marker on both pages */
  270.                         {
  271.                             DrawChar(PAGE_0, s, 2, BLACK, 0x10);
  272.                             DrawChar(PAGE_1, s, 2, BLACK, 0x10);
  273.                         }
  274.                         else /* turn off marker on single page */
  275.                         {
  276.                             if (cursor_at == ALPHA) /* disable alpha entry field */
  277.                             {
  278.                                 ColorRectangle(STATIC_PAGE, 88, s-2, 191, s+8, PALE_YELLOW);
  279.                                 DrawString(STATIC_PAGE, s, 11, BLACK, alpha_str);
  280.                             }
  281.                             else if (cursor_at == BETA) /* disable beta entry field */
  282.                             {
  283.                                 ColorRectangle(STATIC_PAGE, 88, s-2, 191, s+8, PALE_YELLOW);
  284.                                 DrawString(STATIC_PAGE, s, 11, BLACK, beta_str);
  285.                             }
  286.  
  287.                             DrawChar(STATIC_PAGE, s, 2, BLACK, 0x10);
  288.                         }
  289.  
  290.                         cursor_at++; /* move cursor and get vertical positioning */
  291.                         s = control_loc[cursor_at];
  292.                         if (cursor_at < HOLDCONT) /* turn on marker on both pages */
  293.                         {
  294.                             DrawChar(PAGE_0, s, 2, RED, 0x10);
  295.                             DrawChar(PAGE_1, s, 2, RED, 0x10);
  296.                         }
  297.                         else /* turn on marker for single page */
  298.                         {
  299.                             if (cursor_at == ALPHA) /* enable alpha entry field */
  300.                             {
  301.                                 ColorRectangle(STATIC_PAGE, 88, s - 2, 191, s + 8, LT_GRAY);
  302.                                 entry_mode = StartEntry(alpha_str, entry_str, s, &cursor_pos);
  303.                             }
  304.                             else if (cursor_at == BETA) /* enable beta entry field */
  305.                             {
  306.                                 ColorRectangle(STATIC_PAGE, 88, s - 2, 191, s + 8, LT_GRAY);
  307.                                 entry_mode = StartEntry(beta_str, entry_str, s, &cursor_pos);
  308.                             }
  309.  
  310.                             DrawChar(STATIC_PAGE, s, 2, RED, 0x10);
  311.                         }
  312.  
  313.                         break;
  314.  
  315.                     case 0x51:    /* PGDN */
  316.                         s = control_loc[cursor_at];
  317.                         if (cursor_at < HOLDCONT) /* turn off marker on both pages */
  318.                         {
  319.                             DrawChar(PAGE_0, s, 2, BLACK, 0x10);
  320.                             DrawChar(PAGE_1, s, 2, BLACK, 0x10);
  321.                         }
  322.                         else /* turn off marker on single page */
  323.                         {
  324.                             if (cursor_at == ALPHA) /* disable alpha entry field */
  325.                             {
  326.                                 ColorRectangle(STATIC_PAGE, 88, s-2, 191, s+8, PALE_YELLOW);
  327.                                 DrawString(STATIC_PAGE, s, 11, BLACK, alpha_str);
  328.                             }
  329.                             else if (cursor_at == BETA) /* disable beta entry field */
  330.                             {
  331.                                 ColorRectangle(STATIC_PAGE, 88, s-2, 191, s+8, PALE_YELLOW);
  332.                                 DrawString(STATIC_PAGE, s, 11, BLACK, beta_str);
  333.                             }
  334.  
  335.                             DrawChar(STATIC_PAGE, s, 2, BLACK, 0x10);
  336.                         }
  337.  
  338.                         cursor_at = bottom_control; /* place cursor at bottom */
  339.                         DrawChar(STATIC_PAGE, control_loc[bottom_control], 2, RED, 0x10);
  340.                         break;
  341.                 }
  342.             }
  343.             else
  344.             {
  345.                 switch (key.c[0])
  346.                 {
  347.                     case '1': /* number entry */
  348.                     case '2':
  349.                     case '3':
  350.                     case '4':
  351.                     case '5':
  352.                     case '6':
  353.                     case '7':
  354.                     case '8':
  355.                     case '9':
  356.                     case '0':
  357.                         if ((cursor_at == ALPHA) || (cursor_at == BETA))
  358.                         {
  359.                             s = control_loc[cursor_at];
  360.                             DrawChar(STATIC_PAGE, s, cursor_pos + 11, LT_GRAY, '_');
  361.                             if (entry_mode == START)
  362.                             {     /* first action upon entering field is typing a number */
  363.                                 cursor_pos = 1;
  364.                                 entry_mode = EDIT_NEW;
  365.                                 DrawString(STATIC_PAGE, s, 11, LT_GRAY, entry_str);
  366.                                 for (i = 0; i < 11; i++)
  367.                                     entry_str[i] = ' ';
  368.                             }
  369.                             else if (cursor_pos == 12) /* end of entry field */
  370.                             {
  371.                                 DrawChar(STATIC_PAGE, s, cursor_pos + 11, BLACK, '_');
  372.                                 break;
  373.                             }
  374.                             else if (!cursor_pos)
  375.                             { /* no numbers allowed as first character position in field */
  376.                                 entry_str[0] = ' ';
  377.                                 cursor_pos = 1;
  378.                             }
  379.  
  380.                             DrawChar(STATIC_PAGE, s, cursor_pos + 11, LT_GRAY,
  381.                                                                                             entry_str[cursor_pos]);
  382.                             entry_str[cursor_pos] = key.c[0];
  383.                             DrawChar(STATIC_PAGE, s, cursor_pos++ + 11, BLACK, key.c[0]);
  384.                             DrawChar(STATIC_PAGE, s, cursor_pos + 11, BLACK, '_');
  385.                             entry_str[cursor_pos] = '\0'; /* pad in new null */
  386.                         }
  387.                         break;
  388.  
  389.                     case '-':
  390.                     case '.':
  391.                         if ((cursor_at == ALPHA) || (cursor_at == BETA))
  392.                         {
  393.                             s = control_loc[cursor_at];
  394.                             DrawChar(STATIC_PAGE, s, cursor_pos + 11, LT_GRAY, '_');
  395.                             if (entry_mode == START)
  396.                             { /* first action upon entering field is typing a '.' or '-' */
  397.                                 entry_mode = EDIT_NEW;
  398.                                 DrawString(STATIC_PAGE, s, 11, LT_GRAY, entry_str);
  399.                                 for (i = 0; i < 11; i++)
  400.                                     entry_str[i] = ' ';
  401.  
  402.                                 if (key.c[0] == '.') /* insert leading '0' first */
  403.                                 {
  404.                                     cursor_pos = 2;
  405.                                     entry_str[1] = '0';
  406.                                     DrawChar(STATIC_PAGE, s, 12, BLACK, '0');
  407.                                 }
  408.                                 else
  409.                                     cursor_pos = 0;
  410.                             }
  411.                             else if ((key.c[0] == '-') && (cursor_pos != 0))
  412.                             {
  413.                                 DrawChar(STATIC_PAGE, s, cursor_pos + 11, BLACK, '_');
  414.                                 break;
  415.                             }
  416.                             else if (key.c[0] == '.')
  417.                             {
  418.                                 if (cursor_pos > 2)
  419.                                 {               /* only allow '.' entry at position 0 or 1 */
  420.                                     DrawChar(STATIC_PAGE, s, cursor_pos + 11, BLACK, '_');
  421.                                     break;
  422.                                 }
  423.                                 else
  424.                                 {
  425.                                     switch (cursor_pos)
  426.                                     {
  427.                                         case 0: /* insert leading blank */
  428.                                             DrawChar(STATIC_PAGE, s, 11, LT_GRAY, entry_str[0]);
  429.                                             DrawChar(STATIC_PAGE, s, 12, BLACK, ' ');
  430.                                             entry_str[0] = ' ';
  431.                                         case 1: /* insert leading '0' */
  432.                                             DrawChar(STATIC_PAGE, s, 12, LT_GRAY, entry_str[1]);
  433.                                             DrawChar(STATIC_PAGE, s, 12, BLACK, '0');
  434.                                             entry_str[1] = '0';
  435.                                             cursor_pos = 2;
  436.                                     }
  437.                                 }
  438.                             }
  439.  
  440.                             DrawChar(STATIC_PAGE, s, cursor_pos + 11, LT_GRAY,
  441.                                                                                             entry_str[cursor_pos]);
  442.                             entry_str[cursor_pos] = key.c[0];
  443.                             DrawChar(STATIC_PAGE, s, cursor_pos++ + 11, BLACK, key.c[0]);
  444.                             DrawChar(STATIC_PAGE, s, cursor_pos + 11, BLACK, '_');
  445.                             entry_str[cursor_pos] = '\0';
  446.                         }
  447.                         break;
  448.  
  449.                     case '\b': /* backspace and delete character */
  450.                         if (((cursor_at == ALPHA) || (cursor_at == BETA)) && cursor_pos)
  451.                         {
  452.                             s = control_loc[cursor_at];
  453.                             DrawChar(STATIC_PAGE, s, cursor_pos-- + 11, LT_GRAY, '_');
  454.                             DrawChar(STATIC_PAGE, s, cursor_pos + 11, LT_GRAY,
  455.                                                                                             entry_str[cursor_pos]);
  456.                             DrawChar(STATIC_PAGE, s, cursor_pos + 11, BLACK, '_');
  457.                             entry_str[cursor_pos] = '\0';
  458.                             if (entry_mode == START)
  459.                                 entry_mode = EDIT_OLD;
  460.                         }
  461.                         break;
  462.  
  463.                     case '\r': /* enter key */
  464.                         switch(cursor_at)
  465.                         {
  466.                             case HOLDCONT: /* toggle HOLD and CONTINUE modes */
  467.                                 if (hold)
  468.                                 {
  469.                                     hold = FALSE; /* resume page flipping */
  470.                                     i = control_loc[cursor_at];
  471.                                     DrawString(STATIC_PAGE, i, 4, PALE_YELLOW, "CONT");
  472.                                     DrawString(STATIC_PAGE, i, 4, BLACK, "HOLD");
  473.                                 }
  474.                                 else
  475.                                 {
  476.                                     hold = TRUE; /* stop page flipping */
  477.                                     i = control_loc[cursor_at];
  478.                                     DrawString(STATIC_PAGE, i, 4, PALE_YELLOW, "HOLD");
  479.                                     DrawString(STATIC_PAGE, i, 4, BLACK, "CONT");
  480.                                     if (looking_at == PAGE_0)
  481.                                         source_page = PAGE_0_START+0xe74;
  482.                                     else
  483.                                         source_page = PAGE_1_START+0xe74;
  484.                                 }
  485.  
  486.                                 break;
  487.  
  488.                             case RUNHALT: /* toggle RUN and HALT modes */
  489.                                 if (DSPrunning)
  490.                                 {
  491.                                     HaltDSP(); /* stop real-time fast wavelet transform */
  492.                                     i = control_loc[cursor_at];
  493.                                     DrawString(STATIC_PAGE, i, 4, PALE_YELLOW, "HALT");
  494.                                     DrawString(STATIC_PAGE, i, 4, BLACK, "RUN");
  495.  
  496.                                     /* restore access to ALPHA, BETA, and QUIT controls */
  497.                                     i = control_loc[ALPHA];
  498.                                     DrawString(STATIC_PAGE, i, 4, BLACK, "ALPHA");
  499.                                     DrawChar(STATIC_PAGE, i, 2, BLACK, 0x10);
  500.  
  501.                                     i = control_loc[BETA];
  502.                                     DrawString(STATIC_PAGE, i, 4, BLACK, "BETA");
  503.                                     DrawChar(STATIC_PAGE, i, 2, BLACK, 0x10);
  504.  
  505.                                     i = control_loc[QUIT];
  506.                                     DrawString(STATIC_PAGE, i, 4, BLACK, "QUIT");
  507.                                     DrawChar(STATIC_PAGE, i, 2, BLACK, 0x10);
  508.                                     bottom_control = QUIT; /* all controls accessible */
  509.                                   DSPrunning = FALSE;
  510.                                 }
  511.                                 else /* start real-time fast wavelet transform */
  512.                                 {
  513.                                     DSPrunning = TRUE;
  514.                                     bottom_control = RUNHALT;
  515.                                     if (looking_at == PAGE_0) /* setup for page flipping */
  516.                                         source_page = PAGE_0_START+0xe74;
  517.                                     else
  518.                                         source_page = PAGE_1_START+0xe74;
  519.  
  520.                                     i = control_loc[cursor_at];
  521.                                     DrawString(STATIC_PAGE, i, 4, PALE_YELLOW, "RUN");
  522.                                     DrawString(STATIC_PAGE, i, 4, BLACK, "HALT");
  523.  
  524.                                     /* block access to ALPHA, BETA, and QUIT controls */
  525.                                     i = control_loc[ALPHA];
  526.                                     DrawString(STATIC_PAGE, i, 4, LT_GRAY, "ALPHA");
  527.                                     DrawChar(STATIC_PAGE, i, 2, LT_GRAY, 0x10);
  528.  
  529.                                     i = control_loc[BETA];
  530.                                     DrawString(STATIC_PAGE, i, 4, LT_GRAY, "BETA");
  531.                                     DrawChar(STATIC_PAGE, i, 2, LT_GRAY, 0x10);
  532.  
  533.                                     i = control_loc[QUIT];
  534.                                     DrawString(STATIC_PAGE, i, 4, LT_GRAY, "QUIT");
  535.                                     DrawChar(STATIC_PAGE, i, 2, LT_GRAY, 0x10);
  536.                                     RunDSP();
  537.                                 }
  538.                                 break;
  539.  
  540.                             case ALPHA:
  541.                                 if (cursor_pos < 2) /* some value must be available */
  542.                                     break;
  543.  
  544.                                 entry = atof(entry_str);
  545.                                 if (entry != alpha) /* take only new values */
  546.                                 {
  547.                                     entry_mode = START;
  548.                                     i = 0;
  549.                                     if ((entry > pi) || (entry < -pi)) /* rejection range */
  550.                                     {
  551.                                         DrawString(STATIC_PAGE, s, 11, LT_GRAY, entry_str);
  552.                                         DrawChar(STATIC_PAGE, s, cursor_pos + 11, LT_GRAY, '_');
  553.                                         entry_mode =
  554.                                                         StartEntry(alpha_str, entry_str, s, &cursor_pos);
  555.                                         break; /* reinstate the original value */
  556.                                     }
  557.  
  558.                                     alpha = entry; /* accept new value */
  559.                                     CopyString(entry_str, alpha_str, 12);
  560.                                     /* make new filters and functions */
  561.                                     BuildDSPfilterArray(alpha, beta, wavefilters);
  562.                                     switch(filtlen)
  563.                                     {
  564.                                         case 2:
  565.                                             DSPfiltlen = FILTER_LENGTH_2;
  566.                                             break;
  567.  
  568.                                         case 4:
  569.                                             DSPfiltlen = FILTER_LENGTH_4;
  570.                                             break;
  571.  
  572.                                         case 6:
  573.                                             DSPfiltlen = FILTER_LENGTH_6;
  574.                                     }
  575.  
  576.                                     /* download new values to DSP board */
  577.                                     DownloadDecompCoeffs(DSPfiltlen);
  578.                                     DownloadFiltCoeffs(wavefilters);
  579.                                     DrawObject(STATIC_PAGE, wavelet_window);
  580.                                     DrawGraph(209, 5, 531, 65, PhiData + offset, magnitude,
  581.                                                                                                                             320, OLIVE, 1);
  582.                                     DrawGraph(209, 5, 531, 65, PsiData + offset, magnitude,
  583.                                                                                                                             320, CYAN, 1);
  584.                                 }
  585.                                 break;
  586.  
  587.                             case BETA:
  588.                                 if (cursor_pos < 2) /* some value must be available */
  589.                                     break;
  590.  
  591.                                 entry = atof(entry_str);
  592.                                 if (entry != beta) /* take only new values */
  593.                                 {
  594.                                     entry_mode = START;
  595.                                     i = 0;
  596.                                     if ((entry > pi) || (entry < -pi)) /* rejection range */
  597.                                     {
  598.                                         DrawString(STATIC_PAGE, s, 11, LT_GRAY, entry_str);
  599.                                         DrawChar(STATIC_PAGE, s, cursor_pos + 11, LT_GRAY, '_');
  600.                                         entry_mode =
  601.                                                         StartEntry(beta_str, entry_str, s, &cursor_pos);
  602.                                         break; /* reinstate the original value */
  603.                                     }
  604.  
  605.                                     beta = entry;
  606.                                     CopyString(entry_str, beta_str, 12);
  607.                                     /* make new filters and functions */
  608.                                     BuildDSPfilterArray(alpha, beta, wavefilters);
  609.                                     switch(filtlen)
  610.                                     {
  611.                                         case 2:
  612.                                             DSPfiltlen = FILTER_LENGTH_2;
  613.                                             break;
  614.  
  615.                                         case 4:
  616.                                             DSPfiltlen = FILTER_LENGTH_4;
  617.                                             break;
  618.  
  619.                                         case 6:
  620.                                             DSPfiltlen = FILTER_LENGTH_6;
  621.                                     }
  622.  
  623.                                     /* download new values to DSP board */
  624.                                     DownloadDecompCoeffs(DSPfiltlen);
  625.                                     DownloadFiltCoeffs(wavefilters);
  626.                                     DrawObject(STATIC_PAGE, wavelet_window);
  627.                                     DrawGraph(209, 5, 531, 65, PhiData + offset, magnitude,
  628.                                                                                                                             320, OLIVE, 1);
  629.                                     DrawGraph(209, 5, 531, 65, PsiData + offset, magnitude,
  630.                                                                                                                             320, CYAN, 1);
  631.                                 }
  632.                                 break;
  633.  
  634.                             case QUIT:
  635.                                 quit = TRUE;
  636.                         }
  637.                         break;
  638.                 }
  639.             }
  640.         }
  641.  
  642.         if (DSPrunning)
  643.         {
  644.             count = WaitDSP(32767);    /* wait for new image to be created */
  645.             new_image = ACKpir16bit(); /* get indicator for image location */
  646.             switch(new_image)          /* determine location of image */
  647.             {
  648.                 case IMAGE_0:
  649.                     image_location = _bitmap0;
  650.                     break;
  651.                 case IMAGE_1:
  652.                     image_location = _bitmap1;
  653.                     break;
  654.                 case NO_NEW_IMAGE:
  655.                     break;
  656.                 default:
  657.                     break;
  658.             }
  659.  
  660.             if (looking_at == PAGE_0)
  661.             {
  662.                 ShiftWaveTraces(source_page, PAGE_1_START+0xe74);
  663.                 SetDMAaddr(image_location);
  664.                 GetDSPimage(PAGE_1_START, _pdr_addr);
  665.                 source_page = PAGE_1_START+0xe74;
  666.                 /* Flip to page 1 */
  667.                 /* adjust the Start Address High register to start
  668.                      screen display on new page */
  669.                 if(!hold)
  670.                 {
  671.                     outport(0x3D4, 0x8b0c);
  672.                     looking_at = PAGE_1;
  673.                 }
  674.             }
  675.             else
  676.             {
  677.                 ShiftWaveTraces(source_page, PAGE_0_START+0xe74);
  678.                 SetDMAaddr(image_location);
  679.                 GetDSPimage(PAGE_0_START, _pdr_addr);
  680.                 source_page = PAGE_0_START+0xe74;
  681.                 /* Flip to page 0 */
  682.                 /* adjust the StartgAddress High and Start Address Low registers
  683.                      to start screen display on page 0 */
  684.                 if(!hold)
  685.                 {
  686.                     outport(0x3D4, 0x170c);
  687.                     looking_at = PAGE_0;
  688.                 }
  689.             }
  690.         }
  691.     } while (!quit);
  692.  
  693.  
  694.     /* Return to text mode and exit */
  695.     regset.x.ax = 0x0003;  /* AL = 3 selects 80x25 text mode */
  696.     int86(0x10, ®set, ®set);
  697. }
  698.